<style type="text/css">
    .product-piece {
        margin-top: 2em;
        width: 100%;
    }

    .number {
        border-radius: 1em;
        height: 2em;
        width: 2em;
        background-color: red;
        border: 1px solid white;
        color: white;
        font-size: 1em;
        position: absolute;
        text-align: center;
        line-height: 2em;
        right: -1em;
        top: -1em;
        z-index: 99;
    }

    .product-piece .img-box {
        margin: auto;
        width: 10em;
        height: 10em;
        position: relative;
    }

    .product-piece .piece-img {
        background-color: red;
        width: inherit;
        height: inherit;
        border-radius: 10px;
    }


</style>
<div class="product-piece">

    <div class="img-box">
        <span class="number piece-id-{$piece.id}" data-piece-id="{$piece.id}">{$piece.number}</span>
        <img class="piece-img" src="{$piece.img_url}"/>
    </div>
    <div>
        <button id="share" class="button">赠送给好友</button>
    </div>
</div>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {

        $('#share').click(function () {
            showNotice();
            $.get('{:url("index/product_piece/share",["piece_id"=>$piece.id])}', function (data) {
                if (data.error_code == 0) {
                    var share_id = data.data.id;
                    var piece_id = "{$piece.id}";
                    var product_id = "{$piece.product_id}";
                    sharePieceToFriend('{$share_info.title}','{$share_info.desc}','{$share_info.img_url}',share_id, piece_id, product_id, function () {
                            //获取剩余数量
                            $.get('{:url("index/product_piece/getNumberByUserId",["piece_id"=>$piece.id])}', function (data) {
                                if (data.error_code == 0) {
                                    changeNumber(piece_id, -1);
                                }
                            })
                            closeDialog();
                        });
                    sharePieceToTimeLine('{$share_info.title}','{$share_info.img_url}',share_id, piece_id, product_id, function () {
                        //获取剩余数量
                        $.get('{:url("index/product_piece/getNumberByUserId",["piece_id"=>$piece.id])}', function (data) {
                            if (data.error_code == 0) {
                                changeNumber(piece_id, -1);
                            }
                        })
                        closeDialog();
                    });
                } else {
                    showDialog(data.msg);
                }
            })
        })

    });

</script>